package edu.nwmissouri.galaxygames;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/*
 * ---A custom ArrayAdapter for use with the Player Life Totals.
 * This adapter allows us to dynamically set the text size of each view in the List View,
 * as well as make other changes, such as TextAlignment, padding, etc.---
 */
public class CustomLifeAdapter extends ArrayAdapter<String>
{
	//---Variables to hold the dimensions of the ListViews
	int listViewHeight;
	int listViewWidth;
	
	//---Variable to hold the size of the text displayed in the ListViews
	float textSize;
	//---A constructor for our CustomLifeAdapter
    public CustomLifeAdapter(Context context, String[] life, int listViewHeight, int listViewWidth){
    	super(context, android.R.layout.simple_list_item_1, life);
    	this.listViewHeight = listViewHeight;
    	this.listViewWidth = listViewWidth;
    }
    
    //---Called each time a View is placed into the ListView as it is populated
    //---This allows us to customize the contents of each view
    public View getView(int position, View convertView, ViewGroup parent) {
    	View row = super.getView(position, convertView, parent);
    	
    	//---Centers the text displayed inside of the ListView
    	((TextView)row).setGravity(Gravity.CENTER);
    	
    	//---Sets the text size according to whether the device is displaying portait or landscape
    	if(listViewWidth > listViewHeight){
    		textSize = (float) (listViewHeight * .40);
    	}else{
    		textSize = (float) (listViewWidth * .50);
    	}
    	
    	//---Set the text size of the View to be 40 or 50 percent the ListView's height
    	((TextView)row).setTextSize(textSize);
    	
    	
    	return row;
    }
}
